package com.wan.uitls

import android.content.Intent
import android.os.Message
import com.google.gson.JsonObject
import com.wan.base.BaseBean
import com.wan.entity.*
import retrofit2.Call
import retrofit2.http.*

/**
 * recyclerView item 点击
 */
interface ItemClickListener {
    fun onItemClickListener(position: Int)
}

/**
 * 点击左侧图片事件
 */
interface ItemRightViewListener {
    fun onRightViewClickListener(position: Int)
}

/**
 * viewPager 的点击事件
 */
interface PagerItemClickListener {
    fun onPagerItemClickListener(position: Int)
}

/**
 * 首页 banner 页面改变
 */
interface PagerChangeListener {
    fun onPageChangeListener(position: Int)
}

interface FlowItemClickListener {
    fun onFlowItemClickListener(position: Int)
}

/**
 * 原来用来处理handler的内部方法的接口
 */
interface HandlerMessageListener {
    fun handlerMessage(message: Message)
}


/**
 * 搜索结果碎片 广播刷新回调接口
 */
interface ResultRefreshDataListener {
    fun onResultRefreshDataListener(intent: Intent)
}

interface QueryTextChangeListener {
    fun onQueryTextChangeListener(intent: Intent)
}

/**
 * 网络接口地址
 */
interface APIServices {
    companion object {
        const val BASE_URL = "http://wanandroid.com/"
    }

    //首页文章列表
    @GET("/article/list/{page}/json")
    fun getArticleList(@Path("page") page: Int): Call<BaseBean<HomeArtEntity>>

    //首页轮播图
    @GET("banner/json")
    fun getHomeBannerList(): Call<BaseBean<ArrayList<HomeBannerEntity>>>

    //项目接口
    @GET("project/tree/json")
    fun getProjectList(): Call<BaseBean<ArrayList<ProjectBean>>>

    //项目下属 碎片接口
    //project/list/1/json?cid=294
    @GET("project/list/{page}/json")
    fun getProjectItemList(@Path("page") page: Int,
                           @Query("cid") cid: Int): Call<BaseBean<HomeArtEntity>>

    //体系下面的数据 tab标题数据
    @GET("tree/json")
    fun getSystemTreeItemList(): Call<BaseBean<ArrayList<SystemTabEntity>>>

    //体系下具体列表 数据
    //article/list/0/json?cid=60
    @GET("article/list/{page}/json")
    fun getSystemArtItemList(@Path("page") page: Int,
                             @Query("cid") cid: Int): Call<BaseBean<HomeArtEntity>>

    //导航下面的数据
    //http://www.wanandroid.com/navi/json
    @GET("navi/json")
    fun getNavigationItemList(): Call<BaseBean<ArrayList<NavigationArtEntity>>>


    //收藏文章列表
    //lg/collect/list/0/json
    @GET("lg/collect/list/{page}/json")
    fun getCollectionList(@Path("page") page: Int, @Header(CommonUtils.Cookie_Send) cookie: String): Call<BaseBean<HomeArtEntity>>


    //收藏站内文章
    //http://www.wanandroid.com/lg/collect/1165/json
    @POST("lg/collect/{id}/json")
    fun postCollectionArticle(@Path("id") id: Int,@Header(CommonUtils.Cookie_Send)cookie: String): Call<JsonObject>


    //取消收藏
    //http://www.wanandroid.com/lg/uncollect_originId/2333/json
    @POST("lg/uncollect_originId/{id}/json")
    fun postUnCollectionArticle(@Path("id") id: Int,@Header(CommonUtils.Cookie_Send)cookie: String): Call<JsonObject>


    //搜索
    // http://www.wanandroid.com/article/query/0/json
    // 参数：
    // 页码：拼接在链接上，从0开始。
    // k ： 搜索关键词
    @POST("article/query/{page}/json")
    fun postSearchArticle(@Path("page") page: Int,
                          @Query("k") k: String): Call<BaseBean<HomeArtEntity>>

    //搜索热词
    //http://www.wanandroid.com/hotkey/json
    @GET("hotkey/json")
    fun getHotKeys(): Call<BaseBean<ArrayList<CommonlyEntity>>>

    //常用网站
    //    http://www.wanandroid.com/friend/json
    @GET("friend/json")
    fun getCommonlyWebSite(): Call<BaseBean<ArrayList<CommonlyEntity>>>


    //登陆
    //user/login
    @FormUrlEncoded
    @POST("user/login")
    fun postLoginData(@Field("username") userName: String,
                      @Field("password") password: String): Call<BaseBean<LoginEntity>>


    //注册
    //user/register
    //username,password,repassword
    @FormUrlEncoded
    @POST("user/register")
    fun postRegisterData(@Field("username") userName: String,
                         @Field("password") password: String,
                         @Field("repassword") repassword: String): Call<BaseBean<LoginEntity>>

    //退出
    //http://www.wanandroid.com/user/logout/json
    @GET("user/logout/json")
    fun getLogoutData(): Call<JsonObject>
}
